package com.seocoo.worker;

import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.seocoo.worker.base.RxOrderRefrect;
import com.seocoo.worker.home.HomeActivity;
import com.sfh.lib.event.BusEventManager;

import cn.jpush.android.api.CmdMessage;
import cn.jpush.android.api.CustomMessage;
import cn.jpush.android.api.JPushMessage;
import cn.jpush.android.api.NotificationMessage;
import cn.jpush.android.service.JPushMessageReceiver;

public class JPushWorkerReceiver extends JPushMessageReceiver {
    private static final String TAG = "MyReceiver";

    @Override
    public void onRegister(Context context, String s) {
        super.onRegister(context, s);
        Log.d("JPushWorkerReceiver","JPushWorkerReceiver 注册成功回调 onRegister() :"+s);
    }

    @Override
    public void onCommandResult(Context context, CmdMessage cmdMessage) {
        super.onCommandResult(context, cmdMessage);
        Log.d("JPushWorkerReceiver","JPushWorkerReceiver 注册失败回调 onCommandResult() :"+cmdMessage);
    }

    @Override
    public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) {
        super.onAliasOperatorResult(context, jPushMessage);
        Log.d("JPushWorkerReceiver","JPushWorkerReceiver onAliasOperatorResult() jPushMessage:"+jPushMessage);
    }

    @Override
    public void onMessage(Context context, CustomMessage customMessage) {
        super.onMessage(context, customMessage);
        Log.d("JPushWorkerReceiver","JPushWorkerReceiver 收到自定义消息回调 onMessage() customMessage:"+customMessage);
    }

    @Override
    public void onNotifyMessageArrived(Context context, NotificationMessage notificationMessage) {
        super.onNotifyMessageArrived(context, notificationMessage);
        //收到通知回调
        Log.d("JPushWorkerReceiver","JPushWorkerReceiver 收到通知回调 onNotifyMessageArrived() notificationMessage:"+notificationMessage.notificationTitle);
        BusEventManager.postEvent(new RxOrderRefrect());
    }

    @Override
    public void onNotifyMessageOpened(Context context, NotificationMessage notificationMessage) {
        super.onNotifyMessageOpened(context, notificationMessage);
        Log.d("JPushWorkerReceiver","JPushWorkerReceiver 点击通知回调 onNotifyMessageOpened() notificationMessage:"+notificationMessage.notificationTitle);
        //点击通知回调
        Intent intent = new Intent(context, HomeActivity.class);
        intent.putExtra("action","open.order");
        intent.putExtra("index", 0);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }
}
